/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import br.com.systemcar.dao.UsuarioDao;
import br.com.systemcar.model.Usuario;
import javassist.bytecode.stackmap.BasicBlock;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import javax.inject.Inject;

/**
 *
 * @author danilo
 */
@FacesValidator(value="vldlogin")
public class ValidatorUser implements Validator{
    Usuario user = new Usuario();
    @Inject
    UsuarioDao usuerDao;

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        
        try{
         user = usuerDao.findUser(value.toString());
        }catch(Exception e){
            FacesMessage msg = 
		new FacesMessage("Usuario ou senha invalidos");
			msg.setSeverity(FacesMessage.SEVERITY_ERROR);
                        throw new ValidatorException(msg);
        }
        

       
    }
    
}
